from app.users import codes as users_codes
from app.users import schema
from common import utils
from common.utils import SessionDep, CurrentUser
from fastapi import APIRouter, Depends
from typing import Annotated, Any

router = APIRouter()


@router.post("/login", response_model=schema.Token, description="登录")
async def login(session: SessionDep, form_data: Annotated[schema.OAuth2RequestForm, Depends()]):
    return users_codes.login_access_token(session, form_data)


@router.post("/login/test-token", description="token身份验证")
def test_token(current_user: CurrentUser) -> Any:
    """
    Test access token
    """
    return current_user


@router.post("/email_sign_up", response_model=utils.ResponseDatas, description="邮箱注册")
async def sign_up_by_email(session: SessionDep, body_data: schema.SignUp):
    return users_codes.register_by_email(session, body_data)


@router.post("/phone_sign_up", response_model=utils.ResponseDatas, description="电话注册")
async def sign_up_by_phone(session: SessionDep, body_data: schema.SignUp):
    return users_codes.register_by_phone(session, body_data)
